#!/usr/bin/env python
import sys
print 'Dive into python'

saveout = sys.stdout
fsock = open('out.log','w')
sys.stdout = fsock
print 'This message will be logged  instead of displayed'
sys.stdout = saveout

fsock.close()
